package com.ygqh.baby.controller.mobile;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.databind.util.JSONPObject;
import com.foxinmy.weixin4j.util.StringUtil;
import com.ygqh.baby.ao.Message;
import com.ygqh.baby.service.YgSubscribeMsgDetailService;

/**
 * 一次性订阅消息
 * 
 * @author guohao
 *
 */
@Controller
@RequestMapping("/mobile/subscribemsg")
public class YgSubscribeMsgController {
	protected final Logger logger = Logger.getLogger(this.getClass());
	@Autowired
	private YgSubscribeMsgDetailService ygSubscribeMsgDetailService;

	@RequestMapping(value = "addSubscribeMsg")
	@ResponseBody
	public JSONPObject addSubscribeMsg(@RequestParam String templateId, @RequestParam String openId, @RequestParam String scene, String action, String callback) {
		if (StringUtil.isNotBlank(action) && action.equals("cancel")) {
			return new JSONPObject(callback, Message.error("当前用户的操作为：取消授权", action));
		}

		ygSubscribeMsgDetailService.addSubscribeMsg(templateId, openId, scene);
		return new JSONPObject(callback, Message.success(1));
	}

}
